package com.hillky.springboot.controller;

import cn.hutool.crypto.SecureUtil;
import com.hillky.springboot.common.Result;
import com.hillky.springboot.controller.dto.LoginDTO;
import com.hillky.springboot.controller.request.AdminPageRequest;
import com.hillky.springboot.controller.request.LoginRequest;
import com.hillky.springboot.controller.request.PassRequest;
import com.hillky.springboot.entity.Admin;
import com.hillky.springboot.entity.User;
import com.hillky.springboot.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
@CrossOrigin
public class AdminController {



    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public Result login(@RequestBody LoginRequest loginRequest){
        LoginDTO loginDTO=adminService.login(loginRequest);
        return Result.success(loginDTO);
    }

    @PutMapping("/password")
    public Result password(@RequestBody PassRequest passRequest){
        adminService.changePassword(passRequest);
        return Result.success();
    }

    @PostMapping("/save")
    public Result save(@RequestBody Admin admin){
        adminService.save(admin);
        return Result.success();
    }

    @PutMapping("/")
    public Result update(@RequestBody Admin admin){
        adminService.update(admin);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        adminService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Admin res = adminService.getById(id);
        return Result.success(res);
    }

    @GetMapping("/list")
    public Result list(){
        List<Admin> res = adminService.list();
        return Result.success(res);
    }

    @GetMapping("/page")
    public Result page(AdminPageRequest adminPageRequest) {
        return Result.success(adminService.page(adminPageRequest));
    }


}
